<template>
  <div class="new-course">
    <div class="new-course-main">
      <div class="new-course-top">
        <div class="title-hot">
          <div class="hot">HOT</div>
          <div class="hot-c"></div>
        </div>
        <div class="title-txt">
          新上好课
        </div>
      </div>
      <ul class="new-course-bottom">
        <li v-for="item in newList" :key="item.id" @click="goDetail(item.id)">
          <img :src="item.courseCover" alt="">
          <div class="course-content">
            <h3>{{ item.courseName }}</h3>
            <div>{{ courseTypeFn(item.courseLevel) }} · {{ item.clicks }}人报名</div>
            <div class="price">
              <div class="price-vip">会员专享</div>
              <div class="price-total">￥ {{ item.discountPrice }}</div>
            </div>
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script setup>
import { mostNew } from '@/utils/api/course'
// hooks
import courseType from '@/hooks/courseType'
const { courseTypeFn } = courseType()
const newList = ref([])
mostNew({
  pageNum: 1,
  pageSize: 8
}).then(res => {
  newList.value = res.data.pageInfo.list
})
// 跳转课程详情页
const router = useRouter()
const goDetail = (id) => {
  router.push({
    path: '/course/detail',
    query: {
      id
    }
  })
}
</script>

<style lang="scss" scoped>
.new-course {
  padding: 38px 0;
  background: #F3F5F9;
}

.new-course-main {
  width: 1000px;
  margin: 0 auto;

  .new-course-top {
    display: flex;
    align-items: center;

    .title-hot {
      display: flex;

      .hot {
        width: 65px;
        height: 25px;
        background: linear-gradient(90deg, #ff727f 0%, #fc685c 100%);
        border-radius: 5px 0 5px 5px;
        text-align: center;
        color: white;
        line-height: 25px;
      }

      .hot-c {
        width: 0;
        height: 0;
        border: 3px solid #fc685c;
        border-bottom-color: transparent;
        border-right-color: transparent;
      }
    }

    .title-txt {
      position: relative;
      z-index: 999;
      margin-left: 11px;
      font-size: 23px;
      color: #333;

      &:after {
        content: '';
        position: absolute;
        bottom: 0;
        left: 0;
        z-index: -1;
        width: 120%;
        margin-left: -10%;
        height: 9px;
        background: linear-gradient(90deg, #fbf8ef 0%, #fea935 100%);
        border-radius: 5px;
      }
    }
  }

  .new-course-bottom {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;

    li {
      box-sizing: border-box;
      width: 240px;
      height: 275px;
      background: #fff;
      box-shadow: 1px 3px 3px rgba(27, 39, 94, .1);
      opacity: 1;
      border-radius: 5px;
      display: flex;
      flex-direction: column;
      float: left;
      margin-top: 38px;

      img {
        width: 240px;
        height: 153px;
      }

      .course-content {
        padding: 7px 16px;

        h3 {
          font-size: 12px;
          color: #333;
        }

        >div {
          font-size: 12px;
          color: #808080;
          padding: 7px 0;
        }

        .price {
          display: flex;

          &-vip {
            width: 64px;
            height: 16px;
            background: linear-gradient(90deg, #ff928e 0%, #fe7062 100%);
            border-radius: 16px 0 16px 0;
            text-align: center;
            color: #fff;
            margin-right: 3px;
          }

          &-total {
            font-size: 12px;
            color: #ff727f;
          }
        }
      }
    }
  }
}
</style>